<?php

namespace api\components;

use api\utils\LogUtil;
use yii\queue\JobInterface;

class BaseJob implements JobInterface
{
    public $id;
    public $status;
    public $args;
    public $metaId;

    const STATUS_WAIT = 0;
    const STATUS_RUNNING = 1;
    const STATUS_FAIL = 2;
    const STATUS_SUCESS = 3;

    public function __construct($args, $jobId = null)
    {
        $this->id = $jobId;
        $this->args = $args;
        $this->metaId = $args['metaId'];
        $this->status = self::STATUS_WAIT;
    }

    public function execute($queue)
    {
        $this->setStatus(self::STATUS_RUNNING);
        LogUtil::warn('job bagin running id: ' . $this->id . 'args: ' . json_encode($this->args), 'components-job');
    }

    public function getId()
    {
        return $this->id;
    }

    public function getStatus()
    {
        return $this->status;
    }

    public function getArgs()
    {
        return $this->args;
    }

    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }

    public function setStatus($status)
    {
        $this->status = $status;
        return $this;
    }

    public function setArgs($args)
    {
        $this->args = $args;
        return $this;
    }
}
